package com.cnhis.cloudhealth.clidoctorweb.basicinformationquery;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.cnhis.cloudhealth.clinical.hosdoctor.doctorordernew.service.IDoctorordernew;
import org.jboss.resteasy.logging.Logger;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cnhis.cloudhealth.clinical.clidoctor.basicinformationquery.service.IBasicInformationQuery;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.util.HttpsClientUtil;
import com.cnhis.cloudhealth.commons.utils.GlobalVariable;
import com.cnhis.cloudhealth.commons.utils.JsonUtil;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

import java.util.HashMap;
import java.util.Map;

@Path("basicinformationquery")
@Component
public class BasicInformationQueryRest
{
    Logger log = Logger.getLogger(BasicInformationQueryRest.class);
    
    @Reference
    private IBasicInformationQuery basicInformationQuery;
    @Reference
    IDoctorordernew iDoctorordernew;
    
    /* ScriptId(7517) */
    /* Description(参数诊疗项目检索) */
    /**
     * 
     * @param ltxt 搜索关键字
     * @return
     * @throws Exception
     */
    @POST
    @Path("treatmentitemquery")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo treatmentItemQuery(@FormParam("ltxt") String ltxt)
        throws Exception
    {
        HashMap map = new HashMap();
        return basicInformationQuery.treatmentItemQuery(map);
    }
    
    /* ScriptId(7492) */
    /* Description(检索处方分类类型) */
    @POST
    @Path("queryprescriptiontype")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo queryPrescriptionType(@FormParam("currPage") int currPage, @FormParam("pageSize") int pageSize)
        throws Exception
    {
        return basicInformationQuery.queryPrescriptionType((currPage - 1) * pageSize, pageSize);
    }
    
    /* Description(调用http服务) */
    @GET
    @Path("sendHttpQuest")
    @Produces({MediaType.APPLICATION_JSON})
    public String sendHttpQuest(@QueryParam("params") String params)
        throws Exception
    {
        Map<String, Object> param = JsonUtil.getMap(params);
        Map<String, String> map = new HashMap<String, String>();
        map.put("phone", GlobalVariable.StringIsNull(param.get("phone")));
        return HttpsClientUtil.getInstance().sendGetRequest(GlobalVariable.StringIsNull(param.get("url")), map);
    }
    
    /* ScriptId(638) */
    /* Description(检索ICD10疾病目录) */
    /**
     * 
     * @param ABW01 性别限制0=不限, 1=男, 2=女
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("illnessdirectory")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo illnessDirectory(@FormParam("ABW01") String ABW01, @FormParam("currPage") int currPage,
        @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("ABW01", ABW01);
        return basicInformationQuery.illnessDirectory(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(1757) */
    /* Description(中医诊断疾病检索) */
    @POST
    @Path("chinesemedicinetreatment")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo chineseMedicineTreatment(@FormParam("currPage") int currPage, @FormParam("pageSize") int pageSize)
        throws Exception
    {
        return basicInformationQuery.chineseMedicineTreatment((currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(2018) */
    /* Description(参数设置中，提取对应的收费项目) */
    /**
     * 
     * @param lBBY01 id
     * @param lAmount 自定义参数
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("feeitem")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo feeItem(@FormParam("lBBY01") int lBBY01, @FormParam("lAmount") int lAmount,
        @FormParam("currPage") int currPage, @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBBY01", lBBY01);
        map.put("lAmount", lAmount);
        return basicInformationQuery.feeItem(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(863) */
    /* Description(医嘱选项设置 缺省药房及发料部门 ) */
    @SuppressWarnings("unchecked")
    @POST
    @Path("defaultpharmacy")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo defaultPharmacy(@FormParam("BAU01") String BAU01, @FormParam("ACF01") int ACF01,
        @FormParam("currPage") int currPage, @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("BAU01", BAU01);
        map.put("ACF01", ACF01);
        return basicInformationQuery.defaultPharmacy(map, (currPage - 1) * pageSize, pageSize);
    }
    
    @GET
    @Path("zhixingkeshi1")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo zhixingkeshi1(@QueryParam("bck01") int bck01)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("bck01", bck01);
        return basicInformationQuery.zhixingkeshi1(map);
    }
    
    @GET
    @Path("getBciInfo")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo getBciInfo(@QueryParam("params") String params)
        throws Exception
    {
        ModelVo mv = new ModelVo();
        try
        {
            Map<String,Object> map = JsonUtil.getMap(params);
            mv = basicInformationQuery.getBciInfo(map);
            mv.setResult(StaticKeys.OH_SUCCESS);
            return mv;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mv.setResultMsg(e.toString());
            mv.setResult(StaticKeys.OH_FALSE);
            return mv;
        }
    }
    
    /**
     * 挂号信息的修改.Clinic_VAC1_Update
     * @param lVAA07 int
     * @param lVAA01 int
     * @param lBCK01 int
     * @param lBCE01 int
     * @param lBCE02 varchar(20)
     * @param lBCE03 varchar(20)
     * @param sign tinyint -- 0：接诊 1: 取消接诊
     * @return
     * @throws Exception
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @POST
    @Path("/updatehoratevac1modify")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo updatehoratevac1modify(@FormParam("mydata") String mydata, @FormParam("VAC01") Long VAC01) throws Exception {
        long startTime = System.currentTimeMillis();
        System.out.println("execvac1Modify开始时间："+startTime+"exec执行时间：**********************************************");
        //Bcb1 bcb1 = new Bcb1();
        Map paramMap = new HashMap();
        paramMap.put("mydata", mydata);
        ModelVo mv = basicInformationQuery.updatehoratevac1modify(paramMap,VAC01);
        long endTime = System.currentTimeMillis()-startTime;
        System.out.println("execvac1Modify执行时间："+endTime+"**********************************************");
        return mv;
    }
    /**
     * 病人信息修改
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @POST
    @Path("/updateVaaVacVcj")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo updateVaaVacVcj(@FormParam("mydata") String mydata, @FormParam("VAC01") Long VAC01) throws Exception {
        Map paramMap = new HashMap();
        paramMap.put("mydata", mydata);
        ModelVo mv = basicInformationQuery.updateVaaVacVcj(paramMap,VAC01);
        return mv;
    }
    
    /**
     * 公共服务REST
     */
    @GET
    @Path("/basequery")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo queryBase(@QueryParam("params") String params) throws Exception {
        Map<String,Object> paramMap = JsonUtil.getMap(params);
        ModelVo mv = basicInformationQuery.queryBase(paramMap);
        return mv;
    }
    
    /**
     * 公共服务REST(分页)
     */
    @GET
    @Path("/basequeryPage")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo basequeryPage(@QueryParam("params") String params) throws Exception {
        Map<String,Object> paramMap = JsonUtil.getMap(params);
        ModelVo mv = basicInformationQuery.basequeryPage(paramMap);
        return mv;
    }

    /**
     * 调用过程不带返回值
     * @param params
     * @param procId
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateProc")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo updateProc(@FormParam("params") String params,@FormParam("procId") String procId) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("params", params);
        map.put("procId", procId);
        ModelVo mv = basicInformationQuery.updateProc(map);
        return mv;
    }
    
    
    /**
     * 调用过程带返回值
     * @param params
     * @param procId
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateProc1")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo updateProc1(@FormParam("params") String params,@FormParam("procId") String procId) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("params", params);
        map.put("procId", procId);
        ModelVo mv = basicInformationQuery.updateProc1(map);
        return mv;
    }
    
    /**
     * 获取分布式ID
     */
    @GET
    @Path("/queryNewId")
    @Produces(MediaType.APPLICATION_JSON)
    public ModelVo queryNewId(@QueryParam("params") String params) throws Exception {
        Map<String,Object> paramMap = JsonUtil.getMap(params);
        ModelVo mv = basicInformationQuery.queryNewId(paramMap);
        return mv;
    }
    /* ScriptId(null)获取卫生材料执行科室*/
    @GET
    @Path("getHygiMaterBck")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo getHygiMaterBck(@QueryParam("lBCK01A") Long lBCK01A,@QueryParam("lBBY01") Long lBBY01) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("lBCK01A",lBCK01A);
        map.put("acf01",1);
        map.put("lBBY01",lBBY01);
        return iDoctorordernew.getHygiMaterBck(map);
    }
}
